﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using QLTT.Models;
using QLTT.Commands;
using System.Windows.Input;
using System.Text.RegularExpressions;
using QLTT.Properties;

namespace QLTT.ViewModels
{
    class FeePaymentViewModel : WorkspaceViewModel, System.ComponentModel.IDataErrorInfo
    {
        private FeePayment _feePayment;
        private icanDataContext _dataContext;
        private Class _class;
        private DelegateCommand _printCommand;
        public FeePaymentViewModel(icanDataContext dataContext)
        {
            _dataContext = dataContext;
            _feePayment = new FeePayment();
            _class = _dataContext.Classes.Where(o => o.ID == _feePayment.Class).Select(o => o).FirstOrDefault();
        }
        public FeePaymentViewModel(icanDataContext dataContext, FeePayment feePayment)
        {
            _feePayment = feePayment;
            _dataContext = dataContext; _class = _dataContext.Classes.Where(o => o.ID == _feePayment.Class).Select(o => o).FirstOrDefault();
        }
        public ICommand PrintCommand
        {
            get
            {
                if (_printCommand == null)
                {
                    _printCommand = new DelegateCommand(Print);
                }
                return _printCommand;
            }
        }
        public long ID
        {
            get { return _feePayment.ID; }
        }
        public string ClassName
        {
            get
            {
                if (_class != null) return _class.Name;
                else return "";
            }
        }
        public Double Amount
        {
            get
            {
                return _feePayment.Amount;
            }
        }
        public DateTime TransactionDate
        {
            get
            {
                return _feePayment.Date;
            }
        }
        public string Reason
        {
            get
            {
                if (_feePayment.Reason == null)
                    return string.Empty;
                return _feePayment.Reason.TrimEnd('\n');
            }
        }
        public byte Months
        {
            get
            {
                return _feePayment.Months;
            }
        }
        private void Print()
        {
            //Print Invoke
            FeePayment oFeePayment = _dataContext.FeePayments.Where(o=>o.ID == this.ID).Select(o=>o).FirstOrDefault();
            StudentInvokeModelView wsInvoke = new StudentInvokeModelView(_dataContext, oFeePayment);
            Mediator.NotifyColleagues<StudentInvokeModelView>(Messages.WorkspaceAdd, wsInvoke);
        }
        #region IDataErrorInfo Members

        public string Error
        {
            get { return null; }
        }

        public string this[string property]
        {
            get
            {
                string msg = null;
                switch (property)
                {
                    default:
                        throw new ArgumentException(
                            Resources.ValidationDefaultException_Error + property);
                }
                return msg;
            }
        }

        #endregion // IDataErrorInfo Members
    }
}
